//@author A0105740R

package rightnow.parser.cmdline;

import rightnow.parser.cmdline.CommandType;

/**
 * This parser parses arguments for command "edit".
 */
final class CmdEditParser {
	
	private static final int POSITION_INDEX = 0;
	private static final int POSITION_OTHER = 1;
	
	private static final int NUM_ARG_WITH_TASK_CONTENT = 2;
	private static final int NUM_MAX_SPLIT = 2;
	
	/**
	 * Parses an argument string and stores the result in a command parser bucket.
	 * @param bucket != null
	 * @param text != null
	 * @throws CmdParserException
	 */
	public static void parseInto(CmdParserBucket bucket, String text) 
			throws CmdParserException {	
		String tokens[] = text.split("\\s+", NUM_MAX_SPLIT);
		
		try {
			bucket.setInt(Integer.parseInt(tokens[POSITION_INDEX]));
		}
		catch (NumberFormatException e) {
			throw new CmdParserException(CmdParserErrorMsg.ERROR_FORMAT_INDEX);
		}
		
		if (tokens.length < NUM_ARG_WITH_TASK_CONTENT) {
			bucket.setCmdType(CommandType.EDIT_INIT);
			return;
		}
		
		bucket.setTask(CmdTaskParser.INSTANCE.parse(tokens[POSITION_OTHER]));
	}

}
